<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Vue事件绑定</title>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
</head>
<body>
<style>
    .active {
        border: 1px solid red;
    }
</style>

<div id="app">
    <button v-on:click="sayHi">click me!</button>
    <button @click="sayHi">简单写法</button>
    <button @dblclick="sayHi">双击事件</button>
    <h2 @click="changeFood" :class="{active:isActive}">{{food}}</h2>
</div>

<script>
    let vue = new Vue({
        el: "#app",
        data: {
            msg: "vue",
            food: "西兰花炒蛋",
            isActive: false
        },
        methods: {
            sayHi: function () {
                alert(this.msg)
            },
            changeFood: function () {
                console.log(this.food)
                this.food = "新版西兰花炒蛋"
                this.isActive = !this.isActive
            }
        }
    });
</script>

</body>
</html>